package com.yanqu.road.server.timer;

import com.yanqu.road.server.CrossBaseServer;
import com.yanqu.road.server.TempCrossMgr;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.executor.GeneralTask;

public class MgrRemoveDataTask extends GeneralTask {

    @Override
    public void doRun() {
        for (TempMgr baseMgr : CrossBaseServer.getInstance().getMgrList()) {
            if(baseMgr instanceof TempCrossMgr){
                try {
                    long startTime = System.currentTimeMillis();
                    ((TempCrossMgr) baseMgr).removeExpireData();
                    long cost = System.currentTimeMillis() - startTime;
                    getLOGGER().info("{} removeData cost {} mills.", baseMgr.getClass().getSimpleName(), cost);
                } catch (Exception e) {
                    getLOGGER().error("{} removeData error.", baseMgr.getClass().getSimpleName(), e);
                }
            }
        }

        try {
            long zeroTimeStamp = DateHelper.getTodayZeroTimeStamp();
            long startTime = zeroTimeStamp + 22 * DateHelper.HOUR_MILLIONS;
            long beforeTime = zeroTimeStamp + 23 * DateHelper.HOUR_MILLIONS + 50 * DateHelper.MINUTE_MILLIONS;
            long currentTime = DateHelper.getCurrentTime();
            if (startTime < currentTime && currentTime < beforeTime) {
                ActivityMgr.loadActivity();
                getLOGGER().info("CrossMgr loadActivity success.");
            }
        } catch (Exception e) {
            getLOGGER().error("CrossMgr removeData error.", e);
        }
    }

}
